CFLAGS = -g
CXXFLAGS = -g 
LDFLAGS = -lpthread -lrt -lnspr4

# define the correct directories for 3rd-party libraries
# ptypes
PTYPES_FLAGS = -Iptypesdir
# Berkeley DB
DB_FLAGS = -Idbincdir
DB_LDFLAGS = -Ldblibdir -ldb

TARGETS = ex01.o ex02aa ex02b ex02c.class ex02da.o ex02db ex02e.o \
	ex02fa.o ex02fb.o ex02fc.o ex02fd.o ex03aa ex03ab ex03ac ex03ad ex03af \
	ex03aea ex03ag ex03ah ex03ai ex03aj ex03b ex03cb ex03cc ex03cd \
	ex03ce ex03cf ex03cg ex03ch.o ex03ci.o ex03cj.o ex03ck \
	ex03cl ex03d ex03e.o  \
	ex03f ex03g ex03h ex03i ex03j ex03k.o ex03.o \
	ex04aa ex04ab ex04ac ex04ad ex04ae ex04b ex04ca ex04cc ex04cd \
	ex04ce ex04cf.o ex04cg ex04ch ex04ci.o ex04cj ex04ck.o ex04cl \
	ex04cm ex04da ex04db ex04dc ex04dd.o ex04de.o ex04df.o ex04dg.o \
	ex04dh ex04di.o ex04dj ex05a ex05ba ex05bc ex05bd ex05c ex05da.o \
	ex05db.o ex05dc ex05dd.o ex05de ex05e.o ex05fa.o ex05fb.o ex05fca ex05fd \
	ex05fe ex05ff ex05fg ex05fga ex05ga ex05gb ex05gc.o ex05h \
	ex06aa.o ex06ab ex06ad.o ex06af ex06ba.o ex06bc.o ex06bd.o \
	ex06be.o ex06d.o ex06e.o ex06fa.o ex06fb ex06fc ex07a ex07b

OPTTARGETS = ex06bb.o ex06c

.SUFFIXES:: .class .java .c .cpp .o
.java.class:
	javac $<

all: $(TARGETS)

exttext:
	rm -f extext/*
	./extract.pl -t ./extext *pp *.java

extxml:
	rm -f exxml/*
	./extract.pl -x ./exxml *pp *.java

extbook:
	rm -f exbook/*
	./extbook.pl ./exbook ../0*txt

optional: all $(OPTTARGETS)

clean:
	rm -f *.o *.class $(TARGETS) $(OPTTARGETS)
	rm -f extext/*
	rm -f exxml/*
	rm -f exbook/*

run: all
	./ex02aa
	./ex02b
	./ex02db
	./ex03aa
	./ex03ab
	./ex03ac
	./ex03ad
	./ex03aea
	./ex03af
	./ex03ag
	./ex03ah
	./ex03ai
	./ex03aj
	./ex03b
	./ex03cb
	./ex03cc
	./ex03cd
	./ex03ce
	./ex03cf
	./ex03cg
	./ex03ck
	./ex03cl
	./ex03d
	./ex03f
	./ex03g
	./ex03h
	./ex03i
	./ex03j
	./ex04aa
	./ex04ab
	./ex04ac
	./ex04ad
	./ex04ae
	./ex04b
	./ex04ca
	./ex04cc
	./ex04cd
	./ex04ce
	./ex04cg
	./ex04ch
	./ex04cj
	./ex04cl
	./ex04cm
	./ex04da
	./ex04db
	./ex04dc
	./ex04dh
	./ex04dj
	time ./ex05a
	./ex05ba
	./ex05bc
	./ex05bd
	time ./ex05c
	./ex05dc
	./ex05de
	./ex05fca
	./ex05fd
	./ex05fe
	./ex05ff
	./ex05fg
	./ex05fga
	./ex05ga
	./ex05gb
	./ex05h
	./ex06ab
	./ex06af
	./ex06fb
	./ex06fc

runopt: run
	./ex06c

ex06bb.o: ex06bb.cpp
	$(CXX) $(CXXFLAGS) $(PTYPES_FLAGS) -c $<

ex06c: ex06c.cpp
	$(CXX) $(CXXFLAGS) $(DB_FLAGS) -o $@ $< $(DB_LDFLAGS) $(LDFLAGS)

